import { configure, getLogger } from 'log4js';
import init_ai from './ai';
import { IActions, IEvents } from './interfaces';
import config from './utils/config';
import init_events from './utils/init-app-event';

const FD_EVENTS_INIT = 'fd-events-init';

export default function init(events: IEvents, actions: IActions) {
	configure(config.LOG_CONF);

	const logger = getLogger();

	console.log = logger.info.bind(logger) as (message?: any, ...optionalParams: any[]) => void;
	console.debug = logger.info.bind(logger) as (message?: any, ...optionalParams: any[]) => void;
	console.info = logger.info.bind(logger) as (message?: any, ...optionalParams: any[]) => void;
	console.warn = logger.info.bind(logger) as (message?: any, ...optionalParams: any[]) => void;
	console.error = logger.info.bind(logger) as (message?: any, ...optionalParams: any[]) => void;

	const ai = init_ai({}, actions, events);
	init_events(events, ai.emit);
	return ai.emit(FD_EVENTS_INIT);
}
